<template>
	<view>
		<u-navbar
			title="工单详情"
			:autoBack="true"
			placeholder
		>
		</u-navbar>
		<scroll-view :scroll-y="true" :style="{height: scrollViewHeight}">
			<template v-if="loading">
				<view style="padding: 32rpx;">
					<u-skeleton avatarSize="48" avatarShape="square" style="margin-bottom: 32rpx;" :loading="loading" avatar rows="7" v-for="i in 8" :key="i"></u-skeleton>
				</view>
			</template>
			<template v-else>
				<u--form labelPosition="left" :model="model" ref="form1">
					<view style="padding: 0 32rpx;background-color: #fff;">
						<u-form-item labelWidth="80" label="工单位置" borderBottom ref="phone">
							<text>{{detail1.dormitoryId_dictText}}</text>
						</u-form-item>
						<u-form-item labelWidth="80" label="工单状态" borderBottom ref="phone">
							<text :style="{color: appColor}">{{detail1.status_dictText}}</text>
						</u-form-item>
						<u-form-item labelWidth="80" label="任务名称" borderBottom ref="refundPrice">
							<text>{{detail.workCategory_dictText}}</text>
						</u-form-item>
						<u-form-item labelWidth="80" label="任务类型" borderBottom ref="phone">
							<text>{{detail.workOrder_dictText}}</text>
						</u-form-item>
						<view style="color: #303133;font-size: 15px;padding-top: 10px;">备注信息</view>
						</u-form-item>
						<u-form-item borderBottom labelWidth="0" style="position: relative;top: -16rpx;">
							<view>{{detail1.remark}}</view>
						</u-form-item>
						<u-form-item labelWidth="160" label="工单照片" ref="img">
						</u-form-item>
						<u-upload
								:deletable="false"
								:fileList="fileList1"
								@afterRead="afterRead"
								@delete="deletePic"
								name="1"
								multiple
								:maxCount="fileList1.length"
							></u-upload>
					</view>
				</u--form>
			</template>
			
		</scroll-view>
	</view>
</template>

<script>
	import {mapState, mapActions} from 'vuex';
	import {getToken} from '@/utils/auth.js';
	import {base_url} from '@/utils/request.js';
	import {listAdoptWorkTaskDetailByMainId} from '@/api/me.js';
	export default {
		data() {
			return {
				dataList: [],
				actions: [],
				showReason: false,
				model: {
					refund: {
						remark: '',
					},
				},
				fileList1: [],
				orderId: undefined,
				loading: true,
				detail1: {
					remark: '',
				}
			}
		},
		computed: {
			...mapState(['appInfo', 'detail']),
			appColor() {
				return this.appPrimaryColor
			},
			scrollViewHeight() {
				return this.scrollHeight - 44 + 'px';
			},
		},
		onLoad({id}) {
			this.loading = true;
			listAdoptWorkTaskDetailByMainId({id}).then(res => {
				this.detail1 = res.result.records[0];
				this.fileList1 = res.result.records[0].image;
			}).finally(() => {
				this.loading = false;
			})
		},
		methods: {
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: base_url + '/jeecg-boot/sys/common/upload', // 仅为示例，非真实的接口地址
						header: {
							'content-type': 'application/json',
							'Login-Type': 'MEMBER',
							'X-Access-Token': getToken(),
						},
						filePath: url,
						name: 'file',
						formData: {
							user: 'test'
						},
						success: (res) => {
							setTimeout(() => {
								resolve(JSON.parse(res.data).message)
							}, 1000)
						}
					});
				})
			},
		}
	}
</script>

<style>
	page {
		background-color: #f5f5f5;
	}
	.u-textarea {
		padding: 9px 0!important;
	}
</style>

<style lang="scss" scoped>
	.shop-cart-box {
		background-color: #fff;
		padding: 32rpx;
		display: flex;
		align-items: center;
		.shop-cart-l {
			display: flex;
			align-items: center;
			width: 72rpx;
		}
		.shop-cart-r {
			flex: 1;
			display: flex;
			.shop-cart-r-1 {
				flex: 1;
				.shop-cart-r-1-title {
					line-height: 34rpx;
					font-size: 28rpx;
					color: #000;
					height: 68rpx;
				}
				.shop-cart-r-1-con {
					height: 48rpx;
					display: flex;
					justify-content: space-between;
					align-items: center;
				}
			}
		}
	}
	
	.logistics-box {
		padding: 32rpx;
		background-color: #fff;
		.logistics-title {
			display: flex;
			align-items: center;
			font-size: 28rpx;
			line-height: 28rpx;
			.logistics-title-l {
				color: #666;
				padding-right: 8rpx;
			}
			.logistics-title-r {
				color: #333;
			}
		}
	}
	
	
	.good-detail-bootom {
		background-color: #ffffff;
		position: fixed;
		height: 50px;
		width: 100vw;
		bottom: 0;
		left: 0;
		padding-bottom: constant(safe-area-inset-bottom);     /*兼容 iOS<11.2*/
		padding-bottom: env(safe-area-inset-bottom);  /*兼容 iOS>11.2*/
		box-sizing: content-box;
		.good-detail-bootom-l1 {
			display: flex;
			flex-direction: column;
			justify-content: center;
			.good-detail-bootom-l1-t {
				font-size: 28rpx;
				padding-bottom: 4rpx;
			}
			.good-detail-bootom-l1-b {
				.good-detail-bootom-l1-b-1 {
					display: flex;
					align-items: center;
					font-size: 24rpx;
				}
			}
		}
		.good-detail-bootom-r {
			flex: 1;
		}
	}
</style>